    <h2 id="数据库-db"> 数据库(db)</h2>
    <p>传统的B/S结构的程序中，除了前端的开发之外，可能还需要有一台服务器、一门后端语言和一个数据库来处理和存储用户数据，这会带来很大的维护成本和可用性的问题。</p>
    <p>uTools的很多插件就像是一个微型的应用程序，总是会碰到一些数据需要持久化存储的场景，为了解决这个问题，我们整合并提供了一个nosql数据库系统，它可以很方便的使用，并在多个设备之间实现秒级同步。</p>
    <h3 id="utools.db.put(Object)<">
        utools.db.put(Object)</h3>
    <ul>
        <li><code>doc</code> Object</li>
        <li><code>返回</code> Object</li>
    </ul>
    <p>执行该方法将会创建或更新数据库文档</p>
    <div class="language-js extra-class">
        <pre class="language-js"><code><span class="token comment">// 创建请求</span>
  utools<span class="token punctuation">.</span>db<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">,</span>
    data<span class="token punctuation">:</span> <span class="token string">"demo"</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token comment">// 返回</span>
  <span class="token punctuation">{</span>id<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">,</span> ok<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> rev<span class="token punctuation">:</span> <span class="token string">"1-05c9b92e6f24287dc1f4ec79d9a34fa8"</span><span class="token punctuation">}</span>
  
  
  <span class="token comment">// 更新请求</span>
  utools<span class="token punctuation">.</span>db<span class="token punctuation">.</span><span class="token function">put</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">,</span>
    data<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">,</span>
    _rev<span class="token punctuation">:</span> <span class="token string">"1-05c9b92e6f24287dc1f4ec79d9a34fa8"</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
  </code></pre>
    </div>
    <p><code>_id</code>代表这个文档在数据库中唯一值，如果值不存在，则会创建一个新的文档，如果值已经存在，则会进行更新。你可能已经注意到，返回对象中包含一个<code>rev</code>属性，这是代表此文档的版本，每次对文档进行更新时，都要带上最新的版本号，否则更新将失败。
    </p>
    <p>另外需要注意，每次更新时都要传入完整的文档数据，无法对单个字段进行更新。</p>
    <h3 id="utools.db.get(string)">
        utools.db.get(string)</h3>
    <ul>
        <li><code>id</code> String</li>
        <li><code>返回</code> Object</li>
    </ul>
    <p>执行该方法将会根据文档ID获取数据</p>
    <div class="language-js extra-class">
        <pre class="language-js"><code><span class="token comment">// 请求</span>
  utools<span class="token punctuation">.</span>db<span class="token punctuation">.</span><span class="token keyword">get</span><span class="token punctuation">(</span><span class="token string">"demo"</span><span class="token punctuation">)</span>
  <span class="token comment">// 返回</span>
  <span class="token punctuation">{</span>_id<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">,</span> _rev<span class="token punctuation">:</span> <span class="token string">"3-9836c5c68af5aef618e17d615882942a"</span><span class="token punctuation">,</span> data<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">}</span>
  </code></pre>
    </div>
    <h3 id="utools.db.remove(string | Object)"> utools.db.remove(string | Object)</h3>
    <ul>
        <li><code>id</code> String | Object</li>
        <li><code>返回</code> Object</li>
    </ul>
    <p>执行该方法将会删除数据库文档，可以传入文档对象或文档id进行操作。</p>
    <div class="language-js extra-class">
        <pre class="language-js"><code><span class="token comment">// 请求</span>
  utools<span class="token punctuation">.</span>db<span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token string">"demo"</span><span class="token punctuation">)</span>
  <span class="token comment">// 返回</span>
  <span class="token punctuation">{</span>id<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">,</span> ok<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> rev<span class="token punctuation">:</span> <span class="token string">"2-effe5dbc23dffc180d8411b23f3108fb"</span><span class="token punctuation">}</span>
  </code></pre>
    </div>
    <h3 id="utools.db.bulkDocs(Array)">
        utools.db.bulkDocs(Array)</h3>
    <ul>
        <li><code>docs</code> Array</li>
        <li><code>返回</code> Array</li>
    </ul>
    <p>执行该方法将会批量更新数据库文档，传入需要更改的文档对象合并成数组进行批量更新。</p>
    <div class="language-js extra-class">
        <pre class="language-js"><code><span class="token comment">// 请求</span>
  utools<span class="token punctuation">.</span>db<span class="token punctuation">.</span><span class="token function">bulkDocs</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo1"</span><span class="token punctuation">,</span>
    data<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">,</span>
    _rev<span class="token punctuation">:</span> <span class="token string">"1-c8817a74e292eda4cba1a45924853af6"</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo2"</span><span class="token punctuation">,</span>
    data<span class="token punctuation">:</span> <span class="token string">"demo"</span><span class="token punctuation">,</span>
    _rev<span class="token punctuation">:</span> <span class="token string">"1-f0399b42cc6123a9cc8503632ba7b3a7"</span>
  <span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">)</span>
  <span class="token comment">// 返回</span>
  <span class="token punctuation">[</span><span class="token punctuation">{</span>
    id<span class="token punctuation">:</span> <span class="token string">"demo1"</span><span class="token punctuation">,</span> ok<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> rev<span class="token punctuation">:</span> <span class="token string">"2-7857b2801bc0303d2cc0bb82e8afd796"</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
    id<span class="token punctuation">:</span> <span class="token string">"demo2"</span><span class="token punctuation">,</span> ok<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> rev<span class="token punctuation">:</span> <span class="token string">"2-7857b2801bc0303d2cc0bb82e8afd796"</span>
  <span class="token punctuation">}</span><span class="token punctuation">]</span>
  </code></pre>
    </div>
    <h3 id="utools.db.allDocs(String|Array)"> utools.db.allDocs(String|Array)</h3>
    <ul>
        <li><code>preKey</code> String | []</li>
        <li><code>返回</code> Array</li>
    </ul>
    <p>执行该方法将会获取所有数据库文档，如果传入字符串，则会返回以字符串开头的文档，也可以传入指定ID的数组，不传入则为获取所有文档。</p>
    <div class="language-js extra-class">
        <pre class="language-js"><code><span class="token comment">// 根据preKey请求</span>
  utools<span class="token punctuation">.</span>db<span class="token punctuation">.</span><span class="token function">allDocs</span><span class="token punctuation">(</span><span class="token string">"demo"</span><span class="token punctuation">)</span>
  <span class="token comment">// 返回</span>
  <span class="token punctuation">[</span><span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo/123"</span><span class="token punctuation">,</span> _rev<span class="token punctuation">:</span> <span class="token string">"2-7857b2801bc0303d2cc0bb82e8afd796"</span><span class="token punctuation">,</span> data<span class="token punctuation">:</span> <span class="token string">"demo"</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo/124"</span><span class="token punctuation">,</span> _rev<span class="token punctuation">:</span> <span class="token string">"1-f0399b42cc6123a9cc8503632ba7b3a7"</span><span class="token punctuation">,</span> data<span class="token punctuation">:</span> <span class="token string">"demo"</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo/125"</span><span class="token punctuation">,</span> _rev<span class="token punctuation">:</span> <span class="token string">"1-f0399b42cc6123a9cc8503632ba7b3a7"</span><span class="token punctuation">,</span> data<span class="token punctuation">:</span> <span class="token string">"demo"</span>
  <span class="token punctuation">}</span><span class="token punctuation">]</span>
  <span class="token comment">// 根据id数组请求</span>
  utools<span class="token punctuation">.</span>db<span class="token punctuation">.</span><span class="token function">allDocs</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
    <span class="token string">"demo1"</span><span class="token punctuation">,</span>
    <span class="token string">"demo2"</span>
  <span class="token punctuation">]</span><span class="token punctuation">)</span>
  <span class="token comment">// 返回</span>
  <span class="token punctuation">[</span><span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo1"</span><span class="token punctuation">,</span> _rev<span class="token punctuation">:</span> <span class="token string">"2-7857b2801bc0303d2cc0bb82e8afd796"</span><span class="token punctuation">,</span> data<span class="token punctuation">:</span> <span class="token string">"demo"</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span>
    _id<span class="token punctuation">:</span> <span class="token string">"demo2"</span><span class="token punctuation">,</span> _rev<span class="token punctuation">:</span> <span class="token string">"1-f0399b42cc6123a9cc8503632ba7b3a7"</span><span class="token punctuation">,</span> data<span class="token punctuation">:</span> <span class="token string">"demo"</span>
  <span class="token punctuation">}</span><span class="token punctuation">]</span>
  
  </code></pre>
    </div>